#include "tcp_server.hpp"
#include "err.hpp"
#include "daemon.hpp"
#include <iostream>
#include <memory>
using namespace std;
using namespace ns_server;

#include <cstring>

void Usage(string pro)
{
    cout << "Useage\n\t" << pro << " prot\n"
         << endl;
}

string echoserver(const string &str)
{
    return str;
}

//./server port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USE_ERR);
    }
    uint16_t port = atoi(argv[1]);

    unique_ptr<TcpServer> ts(new TcpServer(echoserver, port));

    ts->Init();
    // 将服务器守护进程化
    Daemon();
    ts->Start();

    return 0;
}